<?php require_once('inc.config.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mismatched MySQL Tables</title>
<link href="mismatched.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.remote h1 { color:#F00; }
.remote h2 { color:#F06; padding-left:30px; }
.remote .tables { padding-left:60px; }
.local h1 { color:#00F; }
.local h2 { color:#00F; color:#06C; padding-left:30px; }
.local .tables { padding-left:60px; }
</style>
</head>
<body class="sql">
<?php
$htmls = array(
	'missing' => array(),
	'mismatched' => array(),
	'extra' => array(),
);
$id = 0;
$remote_fields=array();
$local_fields=array();

$remote_extra=array();
$local_extra=array();

foreach($tables as $t => $table)
{
	++$id;
	#echo $table;
	
	$remote = $db_remote->arrays("SHOW FIELDS FROM `{$database_remote}`.`{$table}`;");
	$remote_fields[$table]=array();
	foreach($remote as $r => $field) { $remote_fields[$table][] = $field['Field']; }
	#print_r($remote_fields[$table]);

	$local = $db_local->arrays("SHOW FIELDS FROM `{$database_local}`.`{$table}`;");
	$local_fields[$table]=array();
	foreach($local as $l => $field) { $local_fields[$table][] = $field['Field']; }
	#print_r($local_fields[$table]);
	
	#print_r($remote_fields); print_r($local_fields); die();
	
	#die();
	
	if($remote_fields[$table] == $local_fields[$table]) continue;
	
	sort($remote_fields[$table]);
	sort($local_fields[$table]);
	if($remote_fields[$table] == $local_fields[$table]) continue;
	
	$remote_extra[$table] = array_diff($remote_fields[$table], $local_fields[$table]);
	$local_extra[$table] = array_diff($local_fields[$table], $remote_fields[$table]);
	#print_r($remote_extra[$table]);
	#print_r($local_extra[$table]);
	
	# Clean up empty ones
	if(!$remote_extra[$table]) unset($remote_extra[$table]);
	if(!$local_extra[$table]) unset($local_extra[$table]);
}
#print_r($remote_fields); print_r($local_fields); #die();
#print_r($remote_extra); print_r($local_extra); #die();
?>
<div class="remote">
<h1>Remote - Mismatched</h1>
<?php
	foreach($remote_extra as $table => $fields)
	{
		echo
		"<h2>{$table}</h2>",
		'<div class="tables">', implode("<br>", $fields), '</div>';
	}
?>
</div>
<div class="local">
<h1>Local - Mismatched</h1>
<?php
	foreach($local_extra as $table => $fields)
	{
		echo "<h2>{$table}</h2>",
		'<div class="tables">', implode("<br>", $fields), '</div>';
	}
?>
</div>
</body>
</html>